home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto08 / cfmpfun.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-10-23  |  6.3 KB  |  207 lines

  1. unit Cfmpfun;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, UfMgr17;
  8.  
  9. type
  10.   TCCFMPropsForm = class(TForm)
  11.     Panel1: TPanel;
  12.     CheckBox1: TCheckBox;
  13.     CheckBox2: TCheckBox;
  14.     CheckBox3: TCheckBox;
  15.     Bevel1: TBevel;
  16.     Bevel2: TBevel;
  17.     CheckBox4: TCheckBox;
  18.     CheckBox5: TCheckBox;
  19.     CheckBox6: TCheckBox;
  20.     Panel3: TPanel;
  21.     Label1: TLabel;
  22.     Panel2: TPanel;
  23.     BitBtn1: TBitBtn;
  24.     BitBtn2: TBitBtn;
  25.     BitBtn3: TBitBtn;
  26.     BitBtn4: TBitBtn;
  27.     procedure CheckBox4Click(Sender: TObject);
  28.     procedure CheckBox5Click(Sender: TObject);
  29.     procedure BitBtn4Click(Sender: TObject);
  30.     procedure BitBtn2Click(Sender: TObject);
  31.     procedure BitBtn1Click(Sender: TObject);
  32.     procedure CheckBox6Click(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.     WorkingFileName : String;
  38.     IsADir ,
  39.     IsAnArchive ,
  40.     IsAVolumeID,
  41.     IsAReadOnlyFile,
  42.     IsAHiddenFile ,
  43.     IsASystemFile     : Boolean;
  44.     ThePosition : Integer;
  45.     TheGlobalForm : TCCFileMgrForm;
  46.     procedure Initialize;
  47. end;
  48.  
  49. var
  50.   CCFMPropsForm: TCCFMPropsForm;
  51. implementation
  52.  
  53. uses DRWSUtl3;
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TCCFMPropsForm.Initialize;
  58. begin
  59.   Label1.Caption := ExtractFileName( WorkingFileName );
  60.   CCFileMgrForm.ScrollBox1.TheFWB.GetFileAttributes( WorkingFileName , IsADir ,
  61.    IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  62.     IsASystemFile );
  63.   if IsAVolumeId then
  64.   begin { VolumeID }
  65.     CheckBox1.Checked := false;
  66.     CheckBox2.Checked := false;
  67.     CheckBox3.Checked := false;
  68.     CheckBox4.Checked := false;
  69.     CheckBox5.Checked := true;
  70.     Checkbox6.Checked := false;
  71.     BitBtn1.Enabled := false;
  72.     BitBtn2.Enabled := false;
  73.   end
  74.   else
  75.   begin { Files/Dirs }
  76.     if IsADir then
  77.     begin { Directory }
  78.       if IsASystemFile then CheckBox1.Checked := true else
  79.        CheckBox1.checked := false;;
  80.       If IsAHiddenFile then CheckBox2.Checked := true else
  81.        CheckBox2.checked := false;
  82.       if IsAReadOnlyFile then CheckBox3.Checked := true else
  83.        CheckBox3.checked := false;
  84.       CheckBox4.Checked := true;
  85.       CheckBox5.Checked := false;
  86.       if IsAnArchive then Checkbox6.Checked := true else
  87.        CheckBox6.Checked := false;
  88.       BitBtn1.Enabled := true;
  89.       BitBtn2.Enabled := true;
  90.     end
  91.     else
  92.     begin { File }
  93.       if IsASystemFile then CheckBox1.Checked := true else
  94.        CheckBox1.checked := false;;
  95.       If IsAHiddenFile then CheckBox2.Checked := true else
  96.        CheckBox2.checked := false;
  97.       if IsAReadOnlyFile then CheckBox3.Checked := true else
  98.        CheckBox3.checked := false;
  99.       CheckBox4.Checked := false;
  100.       CheckBox5.Checked := false;
  101.       Checkbox6.Checked := true;
  102.       BitBtn1.Enabled := true;
  103.       BitBtn2.Enabled := true;
  104.     end;
  105.   end;
  106. end;
  107.  
  108. { Delphi wrote this; use it to make sure a directory stays a directory! }
  109. procedure TCCFMPropsForm.CheckBox4Click(Sender: TObject);
  110. begin
  111.   { Ignore any user actions on this box }
  112.   if IsADir then CheckBox4.Checked := true else CheckBox4.Checked := false;
  113. end;
  114.  
  115. { Delphi wrote this; use it to make sure a volume label stays a volume label! }
  116. procedure TCCFMPropsForm.CheckBox5Click(Sender: TObject);
  117. begin
  118.   { Ignore any user actions on this box }
  119.   if IsAVolumeID then CheckBox5.Checked := true else CheckBox5.Checked := false;
  120. end;
  121.  
  122. { Delphi wrote this; use it to get the next selected file, if any }
  123. procedure TCCFMPropsForm.BitBtn4Click(Sender: TObject);
  124. var CurrentName ,                 { Holds work name}
  125.     TheOldString : String;        { Holds Dir      }
  126.     finished     : Boolean;       { Loop control   }
  127.     WorkingDir   : String;        { Holds mod wd   }
  128.     TheFile      : File;          { Generic file v }
  129. begin
  130.   { Get current directory for later }
  131.   GetDir( 0 , WorkingDir );
  132.   { Check for need to add trailing \ }
  133.   if WorkingDir[ Length( WorkingDir )] <> '\' then
  134.    WorkingDir := WorkingDir + '\';
  135.   { Use Generic file getting routine }
  136.   CurrentName := TheGlobalForm.ScrollBox1.GetNextSelection( WorkingDir ,
  137.    ThePosition );
  138.   { if no next file invalidate next button }
  139.   if Currentname = '' then BitBtn4.Enabled := false
  140.   else
  141.   begin { otherwise set up new name }
  142.     WorkingFileName := CurrentName;
  143.     { Reset display }
  144.     Initialize;
  145.     { show it }
  146.     Invalidate;
  147.   end;
  148. end;
  149.  
  150. { Delphi wrote this; use it to clear any user inputs }
  151. procedure TCCFMPropsForm.BitBtn2Click(Sender: TObject);
  152. begin
  153.   { reload file props }
  154.   Initialize;
  155.   { Show results }
  156.   Invalidate;
  157. end;
  158.  
  159. { Delphi wrote this; use it to set the properties of a file from cb's }
  160. procedure TCCFMPropsForm.BitBtn1Click(Sender: TObject);
  161. var TheAttributes : Integer;              { holds attr settings }
  162. begin
  163.   { Take no action on a volume ID }
  164.   if IsAVolumeID then exit;
  165.   { Set a directory's values; can be archive, sys, hid, ro }
  166.   if IsADir then
  167.   begin
  168.     TheAttributes := faDirectory;
  169.     if CheckBox6.Checked then TheAttributes := TheAttributes or faArchive;
  170.     if CheckBox1.Checked then TheAttributes := TheAttributes or faSysFile;
  171.     if CheckBox2.Checked then TheAttributes := TheAttributes or faHidden;
  172.     if CheckBox3.Checked then TheAttributes := TheAttributes or faReadOnly;
  173.   end
  174.   else
  175.   begin  { Set a file's values, can be sys, hid , ro }
  176.     TheAttributes := faArchive;
  177.     if CheckBox1.Checked then TheAttributes := TheAttributes or faSysFile;
  178.     if CheckBox2.Checked then TheAttributes := TheAttributes or faHidden;
  179.     if CheckBox3.Checked then TheAttributes := TheAttributes or faReadOnly;
  180.   end;
  181.   if IsADir then
  182.   begin
  183.     { Set the props via call into FWB }
  184.     TheGlobalForm.ScrollBox1.TheFWB.SetFileAttributes( WorkingFileName ,
  185.      TheAttributes );
  186.   end
  187.   else
  188.   begin
  189.     { Set the props via call into FWB }
  190.     TheGlobalForm.ScrollBox1.TheFWB.SetFileAttributes( WorkingFileName ,
  191.      TheAttributes );
  192.   end;
  193.   { Reset display }
  194.   Initialize;
  195.   { And show it }
  196.   Invalidate;
  197. end;
  198.  
  199. { Delphi wrote this; use it to make sure a non-directory stays one! }
  200. procedure TCCFMPropsForm.CheckBox6Click(Sender: TObject);
  201. begin
  202.   { Ignore any user actions on this box if not a directory }
  203.   if not IsADir then Checkbox6.Checked := true;
  204. end;
  205.  
  206. end.
  207.